-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include tBTC reference in the Acre contract deployment scripts #58
Conversation
Acre contract requires tBTC address as argument. We add `00_resolve_tbtc.ts` script that will ensure tBTC deployment artifact reference is available based on the network. For networks marked with `allowStubs` tag (hardhat local network for running tests) a stub ERC20 contract will be deployed.
Added a script `./scripts/fetch_external_artifacts.sh` that downloads TBTC token deployment artifact from NPM packages for sepolia and mainnet network and places them under `./external` directory where they will be used for contracts deployment.
Ownership of Acre contract will have to be transferred once Acre extends Ownable.
The contract has been renamed from TestToken to TestERC20
Removed `/`to be consistent with other items.
import { ethers } from "ethers" | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function isNonZeroAddress(address: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on replacing with:
export function isValidAddress(address: string): boolean {
try {
ethers.getAddress(address)
} catch (e) {
return false
}
if (ethers.getAddress(address) === ethers.ZeroAddress) {
return false
}
return true
}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean using the isValidAddress
from @keep-network/hardhat-helpers
or updating the implementation here?
@keep-network/hardhat-helpers
is specific for @keep-network
projects and is based on ethers v5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, no need to reference keep-network. Just use the ethers lib and add/replace a check in if (tbtc && isNonZeroAddress(tbtc.address))
with if (tbtc && isValidAddress(tbtc.address))
. It's just to validate that the address should not only be zero, but it's actually valid as well. ethers lib will check it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on replacing with:
export function isValidAddress(address: string): boolean { try { ethers.getAddress(address) } catch (e) { return false } if (ethers.getAddress(address) === ethers.ZeroAddress) { return false } return true }
?
Instead of try catch
we can use isAddress
from ethers:
export function isValidAddress(address: string): boolean {
return (
ethers.isAddress(address) &&
ethers.getAddress(address) !== ethers.ZeroAddress
)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We call ethers.getAddress(address) !== ethers.ZeroAddress
, so the address is validated with ethers.getAddress
.
I added tests to ensure it works as expected: 332d6a9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good, then this function name is misleading a bit. It checks not only if the address is zero, but also other things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the current name isNonZeroAddress
. It describes what the function is used for: check if the address is a non-zero address.
#! /bin/bash | ||
set -eou pipefail | ||
|
||
ROOT_DIR="$(realpath "$(dirname $0)/../")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the realpath
an external or built-in function? After migrating to M2 this command doesn't work for me. If it's external we should mention how to install it in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on M2 and this script worked for me. However, I did the auto-migration from my old Mac copying everything, so maybe it also copied realpath
. It's located in /usr/local/bin/realpath
on my box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Works on my machine™
Updated in 3a05a45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking:
Maybe we should consider adding a prettier for sh
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Rafał Czajkowski <[email protected]>
Co-authored-by: Rafał Czajkowski <[email protected]>
fetch_external_artifact "sepolia" "@keep-network/tbtc-v2" "TBTC" | ||
|
||
# Remove downloaded NPM packages. | ||
rm -rf ${TMP_DIR} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It removes tmp/external-artifacts
, but leaves tmp
. We should remove root tmp
and all the subfolders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally left the main ./tmp
directory in case it contains files from other processes. We remove only the ./tmp/external-artifacts
directory that contains files relevant to this script.
The main ./tmp
was added to .gitignore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally left the main ./tmp directory in case it contains files from other processes.
Then how about adding -d
flag to rm -d tmp
? If it's non-empty then the command won't remove it. If empty, it will. Point is, this script can create a temporary dir on dev's box and if after running the script it's empty, then it will be nice to clean it as well. That's my final comment, if you think otherwise, leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have strong feelings; I'd leave it as is for now and see if we find the current approach painful.
Please feel free to introduce any improvements to the script, though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few minor comments left but they can be addressed later to unblock other PRs
As per #58 (comment) realpath is not available out of the box on OSX. Instead of installing additional package, we changed the way the path is resolved.
Depends on: #58 Improve test fixtures used in Acre contract tests: - use Acre and TBTC contracts deployed with hardhat development scripts (#58) - use unnamed signers as stakers, to not overlap with named signers defined in `hardhat.config.ts`. `ethers.getSigners()` returns all signers, regardless of whether it is a Hardhat named or unnamed account --- This PR contains changes from #62 which were unintentionally merged to this branch.
Depends on #52
Acre contract requires tBTC address as argument.
We add
00_resolve_tbtc.ts
script that will ensure tBTC deploymentartifact reference is available based on the network.
For networks marked with
allowStubs
tag (hardhat local network forrunning tests) a stub ERC20 contract will be deployed.
Added a script
./scripts/fetch_external_artifacts.sh
that downloadsTBTC token deployment artifact from NPM packages for sepolia and mainnet
network and places them under
./external
directory where they will beused for contracts deployment.